
#ifndef GRAPHICS_H
#define GRAPHICS_H

#include "EngineApi.h"
#include "D3DVertex.h"
#include <d3dx9math.h>
#include "VertexManagers.h"
#include <string>
#include "DirectInput.h"

typedef D3DXVECTOR3 Vector3;

enum MATRIX_MODES
{
	WORLD_MATRIX = 0,
	VIEW_MATRIX,
	PROYECTION_MATRIX
};

enum PRIM_TYPE
{
	POINTLIST = D3DPT_POINTLIST,
    LINELIST = D3DPT_LINELIST,
    LINESTRIP = D3DPT_LINESTRIP,
    TRIANGLELIST = D3DPT_TRIANGLELIST,
    TRIANGLESTRIP = D3DPT_TRIANGLESTRIP,
    TRIANGLEFAN = D3DPT_TRIANGLEFAN
};

struct ENGINE_API Texture
{
	std::wstring path;
	UINT width;
	UINT height;
	LPDIRECT3DTEXTURE9 data;
};

class ENGINE_API Graphics
{
private:
	LPDIRECT3D9 m_dxObject;
	LPDIRECT3DDEVICE9 m_dxDevice;
	LPDIRECT3DVERTEXBUFFER9 m_pVertexObject; 

	D3DXMATRIX m_dxMatrix;
	MATRIX_MODES m_currentMatrixMode;

	VertexBuffer<D3DMeshVertex,D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL > m_vertexBuffer;
	IndexBuffer m_indexBuffer;

	Texture* m_lastTexture;
public:
	Graphics();
	bool Init(HWND hwnd);
	void Clear();
	void BeginScene();
	void EndScene();
	void Present(HWND hwnd);
	void DeInit();

	void SetMatrixMode(MATRIX_MODES mode);
	void SetTransform(D3DMATRIX &matrix);
	void LoadIdentity();
	void Scale(Vector3 scale);
	void Translate(Vector3 translation);
	void Rotate(Vector3 rotation);
	
	Texture* LoadTexture(std::wstring path, DWORD colorKey);
	void SetTexture(Texture* pTexture);

	bool DrawElements(USHORT vertexCount, D3DMeshVertex* vertices, USHORT indexCount, USHORT* indices, USHORT primCount, PRIM_TYPE primType);

	bool SetLights(D3DLIGHT9* light);
   bool SetMaterials(D3DMATERIAL9& material);

	LPDIRECT3DDEVICE9 GetDevice() { return m_dxDevice; }
};
#endif // GRAPHICS_H